package co.fitstart.signin.web.controller;


import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import co.fitstart.entity.coach.PrincipalReportRelation;
import co.fitstart.entity.principal.Principal;
import co.fitstart.signin.service.PrincipalService;
import co.fitstart.signin.web.resolver.Secure;

/**
 * 
 * @author Wilson
 * 
 */
@Controller
@RequestMapping("")
public class HomeController {
    
    @Autowired
    private PrincipalService principalService;
    
    
    /**
     * 
     * @return
     */
    @RequestMapping("/home")
    public ModelAndView home(@Secure(property = "id") Long principalId) {
        ModelAndView modelAndView = new ModelAndView("home");
        Principal principal = principalService.load(Principal.class, principalId);
        
        PrincipalReportRelation reportRelation = principalService.getRelation(principal);
        modelAndView.addObject("siteId", reportRelation.getSite().getId());
        return modelAndView;
    }
    
    /**
     * 
     * @param siteId
     * @return
     */
    @RequestMapping("/welcome")
    public ModelAndView welcome(@RequestParam("siteId") Long siteId) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Date date = new Date();
    	String now = sdf.format(date.getTime());
        
        ModelAndView modelAndView = new ModelAndView("welcome");
        modelAndView.addObject("siteId", siteId);
        modelAndView.addObject("now",now);
        return modelAndView;
    }
}
